import { get, post, put, del, userService } from './request'

// 用户相关接口类型定义
export interface User {
  id: number
  username: string
  nickname: string
  phone: string
  email: string
  avatar?: string
  gender: number
  status: number
  address: string
  createTime?: string
}

export interface LoginParams {
  username: string
  password: string
}

export interface RegisterParams {
  username: string
  password: string
  nickname: string
  phone: string
  email: string
  gender: number
  status: number
  address: string
}

// API响应格式
export interface ApiResponse<T> {
  code: number
  message: string
  data: T
}

// 用户登录
export function login(data: LoginParams) {
  return post<ApiResponse<string>>(userService, '/users/login', data)
}

// 用户注册
export function register(data: RegisterParams) {
  return post<ApiResponse<User>>(userService, '/users/register', data)
}

// 获取当前登录用户信息
export function getCurrentUser() {
  return get<ApiResponse<User>>(userService, '/users/current')
}

// 获取用户信息
export function getUserById(id: number) {
  return get<ApiResponse<User>>(userService, `/users/${id}`)
}

// 更新用户信息
export function updateUser(id: number, data: Partial<User>) {
  return put<ApiResponse<User>>(userService, `/users/${id}`, data)
}

// 修改密码
export function changePassword(id: number, oldPassword: string, newPassword: string) {
  return put<ApiResponse<any>>(
    userService, 
    `/users/${id}/password?oldPassword=${encodeURIComponent(oldPassword)}&newPassword=${encodeURIComponent(newPassword)}`
  )
} 